/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.domain.query;

import lombok.*;

import java.time.LocalDateTime;

/**
 * @author wwj
 * @date 2021-2-2
 */
@NoArgsConstructor
@Builder
@Getter
@Setter
@Data
public class DocumentFavoriteQuery {

    private static final int DEFAULT_PAGE_SIZE = 20;
    private static final int MAX_PAGE_SIZE = 1000;

    /**
     * 返回记录的起始位置。
     */
    private Integer offset;

    /**
     * 返回记录的个数。
     */
    private Integer rows;

    /**
     * 收藏人id
     */
    private Long createUserId;

    /**
     * 文档Id
     */
    private Long documentId;

    /**
     * 构建一个查询。
     *
     * @param    pageIndex    页索引
     */
    public DocumentFavoriteQuery(Integer pageIndex) {
        this(pageIndex, DEFAULT_PAGE_SIZE);
    }

    /**
     * 构建一个查询。
     *
     * @param    pageIndex    页索引
     * @param    pageSize    页大小
     */
    public DocumentFavoriteQuery(Integer pageIndex, Integer pageSize) {
        int index = pageIndex == null ? 0 : pageIndex;
        int size = pageSize == null ? DEFAULT_PAGE_SIZE : pageSize;
        this.offset = index * size;
        this.rows = size;
    }

    public DocumentFavoriteQuery(Integer pageIndex, Integer pageSize, Long createUserId){
        this(pageIndex,pageSize);
        this.createUserId = createUserId;
    }

    public DocumentFavoriteQuery(Integer pageIndex, Integer pageSize, Long createUserId,Long documentId){
        this(pageIndex,pageSize);
        this.createUserId = createUserId;
        this.documentId = documentId;
    }

    /**
     * 构造符合条件的查询对象，仅返回一条
     *
     * @return
     */
    public static DocumentFavoriteQueryBuilder one() {
        return DocumentFavoriteQuery.builder().offset(0).rows(1);
    }

    /**
     * 构造符合条件的查询对象，控制返回的记录上限
     *
     * @return
     */
    public static DocumentFavoriteQueryBuilder max() {
        return DocumentFavoriteQuery.builder().offset(0).rows(MAX_PAGE_SIZE);
    }
}
